package com.jc.gateway.entity;


import com.jc.gateway.enums.ResultCodeEnum;
import lombok.Data;

/**
 * @Description: 通用响应结果封装类，用于统一返回接口调用结果（成功或失败），包含状态码、消息和数据。
 * @Author: ASL_ly
 * @Package: com.jc.subject.common.entity
 * @Project: jc-club
 * @Date: 2024/10/21  20:20
 */
@Data
public class Result<T> {

    private Boolean success;
    private Integer code;
    private String message;
    private T data;

    /**
     * 成功，且返回结果不包含数据
     * @return
     */
    public static Result success(){
        Result result = new Result();
        result.setSuccess(true);
        result.setCode(ResultCodeEnum.SUCCESS.getCode());
        result.setMessage(ResultCodeEnum.SUCCESS.getDesc());
        return result;
    }

    /**
     * 成功，且返回结果包含数据
     * @return
     */
    public static <T>Result success(T data){
        Result result = new Result();
        result.setSuccess(true);
        result.setCode(ResultCodeEnum.SUCCESS.getCode());
        result.setData(data);
        result.setMessage(ResultCodeEnum.SUCCESS.getDesc());
        return result;
    }

    /**
     * 失败，且返回结果不包含数据
     * @return
     */
    public static Result fail(){
        Result result = new Result();
        result.setSuccess(false);
        result.setCode(ResultCodeEnum.FAIL.getCode());
        result.setMessage(ResultCodeEnum.FAIL.getDesc());
        return result;
    }

    /**
     * 失败，且返回结果包含数据
     * @return
     */
    public static <T>Result fail(T data){
        Result result = new Result();
        result.setSuccess(false);
        result.setCode(ResultCodeEnum.FAIL.getCode());
        result.setData(data);
        result.setMessage(ResultCodeEnum.FAIL.getDesc());
        return result;
    }

    /**
     * 失败，且直接提供失败码和信息
     * @return
     */
    public static Result fail(Integer code, String message ){
        Result result = new Result();
        result.setSuccess(false);
        result.setCode(code);
        result.setMessage(message);
        return result;
    }



}
